function EnumBase(list){
	var instance=this;
	this.list=list;
	this.display=function(k){
		for ( var i = 0; i < list.length; i++) {
			var vk = list[i];
			if(vk.v==k){
				return vk.t;
			}
		}
	};
	this.render=function(record,index,value){
		return instance.display(value);
	};
	this.rendSelect=function(elemtName,selectVal){
		var str="";
		$.each(list,function(i,item){
			str+="<option value='"+item.v+"'>"+item.t+"</option>"; 
       });
      $("[name="+elemtName+"]").append(str).val(selectVal);
       
	};
}

// 证书状态和类型
function certificate(){
	this.status=new EnumBase([
				{v: '0', 	t:'停用'},
				{v: '1', 	t:'启用'}
	]);
	this.type=new EnumBase([
				{v: '0', 	t:'测试证书'},
				{v: '1', 	t:'线上证书'},
				{v: '2', 	t:'企业证书'}
	]);
	
}

function template(){
	this.status=new EnumBase([
				{v: '0', 	t:'是'},
				{v: '1', 	t:'否'}
	]);
	
}
function channels(){
	this.type=new EnumBase([
	{v:'',t:'请选择渠道'},{v:'1',t:'APNS'},{v:'2',t:'ECHAT'},{v:'3',t:'WEIXIN'},{v:'4',t:'SMS'},{v:'5',t:'EMAIL'},{v:'6',t:'XMPP'},{v:'7',t:'QQ'}
	]);
}
function sendtype(){
	this.type=new EnumBase([
		{v:'0',t:'点对点推送'},{v:'1',t:'全量推送'},{v:'2',t:'群推送'},{v:'3',t:'上传途径'},{v:'4',t:'筛选获取'},{v:'5',t:'域发送'}
	]);
}

//任务状态
function taskstatus(){
	this.type=new EnumBase([
		{v: '0', 	t:'执行中'},
		{v: '1', 	t:'已结束'}
	]);
}

//入队成功失败
function addqueue(){
	this.result=new EnumBase([
		{v: '0', 	t:'成功'},
		{v: '1', 	t:'失败'}
	]);
}
//发送成败
function sendstatus(){
	this.result=new EnumBase([
        {v: '-1', 	t:'请选择状态'},
		{v: '0', 	t:'成功'},
		{v: '1', 	t:'失败'}
	]);
}


// 全局
function epayEnum(){
	this.certificate=new certificate();
	this.template=new template();
	this.channels=new channels();
	this.taskstatus=new taskstatus();
	this.addqueue=new addqueue();
	this.sendtype=new sendtype();
	this.sendstatus=new sendstatus();
	
	this.iniSelect=function(){
		$("select[enum]").each(function(){
			var o="epay_enum."+$(this).attr('enum')+".rendSelect('";
			o=o+this.name+"','"+$(this).attr("v")+"');";
			eval(o);
		});
	};
}
var epay_enum=new epayEnum();

